<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>聚光灯</title>
  <style>
    html {
      font-size: 15px;
    }

    body {
      background-color: #222;
      display: flex;
      justify-content: center;
      align-items: center;
      min-height: 100vh;
    }

    h1 {
      position: relative;
      color: #333;
      font-family: Arial, Helvetica, sans-serif;
      margin: 0;
      padding: 0;
      font-size: 8rem;
      letter-spacing: -0.3rem;
    }

    h1::after {
      content: attr(data-spotlight);
      color: transparent;
      position: absolute;
      top: 0;
      left: 0;
      /* -webkit-clip-path: ellipse(100px 100px at 0% 50%); */
      /* 聚光灯  */
      clip-path: ellipse(100px 100px at 0% 10%);
      animation: spotlight 5s infinite;
      background-image: url('./gradienta-cbE8qwSzuHk-unsplash.jpg');
      background-size: 150%;
      background-position: center center;
      /* 只有文字区域使用background 其他的都裁剪掉*/
      -webkit-background-clip: text;
      /* background-clip: content-box; */
    }

    @keyframes spotlight {

      /* 聚光灯开始位置 */
      0% {
        clip-path: ellipse(100px 100px at 0% 50%);

      }

      50% {
        clip-path: ellipse(100px 100px at 100% 50%);

      }

      /* 聚光灯结束位置(回到开始) */
      100% {
        clip-path: ellipse(100px 100px at 0% 50%);

      }
    }
  </style>
</head>

<body>
  <h1 data-spotlight="HelloWorld!">HelloWorld</h1>
</body>

</html>